package me.wpf.flink;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Properties;

/**
 * Description: 单例加载kafka配置
 *
 * @author 王朋飞
 * @create 2019/5/7
 */
public class KafkaPropertiesHelper {
    private static final Logger logger = LoggerFactory.getLogger(KafkaPropertiesHelper.class);

    private Properties properties;

    private KafkaPropertiesHelper() {
    }

    public static KafkaPropertiesHelper getInstance() {
        return singletonKafkaPropertiesHelper.INSTANCE.getInstance();
    }

    public Properties getProperties() {
        properties = new Properties();
        try {
            properties.load(KafkaPropertiesHelper.class.getResourceAsStream("/kafka.properties"));
        } catch (IOException e) {
            logger.error("Read kafka.properties failure!!!", e);
        }
        return properties;
    }

    private static enum singletonKafkaPropertiesHelper {
        INSTANCE;
        KafkaPropertiesHelper kafkaPropertiesHelper;

        private singletonKafkaPropertiesHelper() {
            kafkaPropertiesHelper = new KafkaPropertiesHelper();
        }

        private KafkaPropertiesHelper getInstance() {
            return kafkaPropertiesHelper;
        }
    }
}
